#include <bits/stdc++.h>
using namespace std;
#define int long long

int n, m, a[500005], sum[500005], l[500005], r[500005];
vector<pair<int, int>> qrs[500005];

struct Frc {
	int a, b;
	bool operator > (const Frc &f) const {
		/*
		   a  fa
		   -  --
		   b  fb
		*/
		return (__int128)a * f.b > (__int128)b * f.a;
	}
	bool operator < (const Frc &f) const {
		return (__int128)a * f.b < (__int128)b * f.a;
	}
	void yf() {
		int gc = __gcd(a, b);
		a /= gc;
		b /= gc;
	}
} qmax[2005][2005], t[500005], ans[500005];

Frc query(int i) {
	Frc ans = {0, 1};
	while (i) {
		ans = max(ans, t[i]);
		i -= (i & (-i));
	}
	return ans;
}

void update(int i, Frc f) {
	for (int j = i; j <= n; j += (j & (-j))) t[j] = max(t[j], f);
}
mt19937 rnd(time(0));
signed main() {
	freopen("value.in", "r", stdin); freopen("value.out", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		sum[i] = sum[i - 1] + a[i];
	}
	for (int i = 0; i < 2005; ++i) for (int j = 0; j < 2005; ++j)
		qmax[i][j].b = 1;
	for (int i = 0; i < 500005; ++i) t[i].b = 1;
	if (n <= 2000) {
		for (int d = 1; d <= n; ++d) {
			for (int l = 1; l + d - 1 <= n; ++l) {
				int r = l + d - 1;
				qmax[l][r] = max({qmax[l + 1][r], qmax[l][r - 1], (Frc){(sum[r] - sum[l - 1]) * (sum[r] - sum[l - 1]), r - l + 1}});
			}
		}
		cin >> m;
		while (m--) {
			int l, r;
			cin >> l >> r;
			qmax[l][r].yf();
			cout << qmax[l][r].a << " " << qmax[l][r].b << "\n";
		}
	} else if (n <= 100000) {
		cin >> m;
		for (int i = 1; i <= m; ++i) {
			cin >> l[i] >> r[i];
			qrs[l[i]].push_back({r[i], i});
		}
		for (int i = n; i >= 1; --i) {
			Frc lst = query(i);
			for (int r = i; r <= min(i + 4399, n); ++r) {
				int sums = sum[r] - sum[i - 1];
				Frc tmp = (Frc){(sums * sums), r - i + 1};
				if (tmp > lst) {
					update(r, tmp);
					lst = tmp;
				}
			}
			for (auto j : qrs[i]) {
				ans[j.second] = query(j.first);
			}
		}
		for (int i = 1; i <= m; ++i) {
			ans[i].yf();
			cout << ans[i].a << " " << ans[i].b << "\n";
		}
	} else {
		cin >> m;
		for (int i = 1; i <= m; ++i) {
			cin >> l[i] >> r[i];
			qrs[l[i]].push_back({r[i], i});
		}
		for (int i = n; i >= 1; --i) {
			Frc lst = query(i);
			for (int r = i; r <= min(i + 2000, n); ++r) {
				int sums = sum[r] - sum[i - 1];
				Frc tmp = (Frc){(sums * sums), r - i + 1};
				if (tmp > lst) {
					update(r, tmp);
					lst = tmp;
				}
			}
			for (auto j : qrs[i]) {
				ans[j.second] = query(j.first);
			}
		}
		for (int i = 1; i <= m; ++i) {
			ans[i].yf();
			cout << ans[i].a << " " << ans[i].b << "\n";
		}
	}
	return 0;
}
